package org.lanqiao.music.system.service.impl;

import org.lanqiao.music.system.entity.UserAlbum;
import org.lanqiao.music.system.dao.UserAlbumDao;
import org.lanqiao.music.system.service.UserAlbumService;
import org.lanqiao.music.system.vo.AllVo;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.PageHelper;
import org.lanqiao.music.common.utils.PageDTO;

import javax.annotation.Resource;
import java.util.List;

/**
 * (UserAlbum)表服务实现类
 *
 * @author makejava
 * @since 2024-08-15 20:55:06
 */
@Service("userAlbumService")
public class UserAlbumServiceImpl implements UserAlbumService {
    @Resource
    private UserAlbumDao userAlbumDao;

    /**
     * 通过ID查询单条数据
     * @return 实例对象
     */
    @Override
    public UserAlbum queryById( ) {
        return this.userAlbumDao.queryById();
    }

    /**
     * 分页查询
     *
     * @param userAlbum 筛选条件
     * @return 查询结果
     */
    @Override
    public PageInfo<UserAlbum> queryByPage(UserAlbum userAlbum, PageDTO pageDTO) {
        PageHelper.startPage(pageDTO.getPageNum(),pageDTO.getPageSize());
        PageInfo page = new PageInfo<>(this.userAlbumDao.queryAllByLimit(userAlbum));
        return page;
    }

    /**
     * 新增数据
     *
     * @param userAlbum 实例对象
     * @return 实例对象
     */
    @Override
    public UserAlbum insert(UserAlbum userAlbum) {
        this.userAlbumDao.insert(userAlbum);
        return userAlbum;
    }

    /**
     * 修改数据
     *
     * @param userAlbum 实例对象
     * @return 实例对象
     */
    @Override
    public UserAlbum update(UserAlbum userAlbum) {
        this.userAlbumDao.update(userAlbum);
        return this.queryById();
    }

    /**
     * 通过主键删除数据
     * @return 是否成功
     */
    @Override
    public boolean deleteById( ) {
        return this.userAlbumDao.deleteById() > 0;
    }

    @Override
    public List<AllVo> getUserFavoriteAlbums(Integer userId) {
        return userAlbumDao.getUserFavoriteAlbums(userId);
    }
}
